package com.ruoyi.system.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.product.ProductDO;
import com.ruoyi.common.entity.VO.product.ProductSearchVO;
import com.ruoyi.common.entity.VO.product.ProductVO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商品 数据层
 *
 * @author lijiantao
 */
public interface IBackProductMapper extends BaseMapper<ProductDO> {

    List<ProductVO> searchList(ProductSearchVO productSearchVO);

    /**
     * 根据商品ID查询信息
     *
     * @param productId 商品ID
     * @return 商品信息
     */
    ProductVO getProductInfoById(Long productId);

    /**
     * 根据商品名称查询商品ID
     */
    @Select("SELECT id FROM product WHERE product_name=#{productName} AND is_delete=0")
    Long getIdByProductName(String productName);

    @Select("SELECT id,buy_price buyPrice,price,has_attribute hasAttribute,order_num orderNum FROM product WHERE is_enable=1 and id=#{productId}")
    ProductDO getProductForSync(Long productId);


    @Select("SELECT shop_id FROM shop_product WHERE is_delete = 0 and product_id=#{productId}")
    List<Long> searchShopProductList(Long productId);

    /**
     * 删除商品
     *
     * @param productId 商品ID
     * @return 结果
     */
    @Update("UPDATE product SET is_delete = 1 WHERE id = #{productId}")
    int deleteProductById(Long productId);

    int multiUpdate(ProductVO productVO);
}
